package RandomPassword;

import java.util.Random;
import java.util.Scanner;

public class RandomPassword {
    public String randomPassword(int length){
        char [] pass = new char[length];
        Random random = new Random();
        for (int i = 0; i < length; i++){
            int choice = random.nextInt(3);
            int lower = random.nextInt(26)+65;
            int upper = random.nextInt(26)+97;
            int number = random.nextInt(10)+48;
            switch (choice){
                case 0 : pass[i] = (char)lower;
                    break;
                case 1 : pass[i] = (char)upper;
                    break;
                case 2 : pass[i] = (char)number;
                    break;
            }
        }
        String password = new String(pass);
        return password;
    }

    public static void main(String[] args) {
        System.out.println("请设定密码长度：");
        Scanner scanner = new Scanner(System.in);
        RandomPassword rp = new RandomPassword();
        System.out.println("随机的密码为："+rp.randomPassword(scanner.nextInt()).toString());
    }
}
